import 'dart:convert';
import 'dart:developer';

import 'package:dio/dio.dart';
import 'package:flutter/material.dart';
import 'package:get_storage/get_storage.dart';
import 'package:jxchmz/API/LoginApi.dart';
import 'package:jxchmz/Getx%E5%B7%A5%E5%85%B7/GetxTools.dart';

class SaleManage  {
  LoginApi loginApi = new LoginApi();
  Dio dio = new Dio();
  var ResponseData;

  // 获取本地token
  configDio() async {
    // 获取本地token
    GetStorage storage = GetStorage();
    String Token =await storage.read("Token");
    print("token:$Token");
    print("账号:${await storage.read("Phone")}");
    print("密码:${await storage.read("Password")}");
    // 构造请求头
    dio.options.contentType="application/json";
    dio.options.headers['Authorization'] = "Bearer $Token";
    dio.options.connectTimeout = 5000;
    dio.options.receiveTimeout = 3000;
  }

  //查询订单和收入
  SalOrderList(data) async {
    //配置dio
    await configDio();
    try {
      ResponseData = await dio.get(loginApi.ApiUrl + "/system/salorder/getNum", queryParameters: data);
      if (ResponseData.statusCode == 200) {
        // 请求成功
        ResponseData = json.decode(ResponseData.toString());
        log("数据返回:$ResponseData");
        return ResponseData;
      } else {
        log("请求失败，状态码:${ResponseData.statusCode}");
        GetxTools().ErrorToast("系统异常");
        return "";
      }
    } catch (e) {
      GetxTools().ErrorToast("系统异常");
      return "";
    }
  }

}

